package com.spider.admin.agent.conf;

import com.spider.admin.conf.ENVConf;
import com.spider.admin.utils.CommonUtil;
import com.spider.admin.utils.FileUtils;
import com.spider.admin.utils.OSCommandUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


public class CommonConf {
    public static String getCommonConfInfo(String serverContextPath, Integer port) {

        String apiServerContext = CommonUtil.getRuntimeIP();

        if (port != null && port != 80) {
            apiServerContext = apiServerContext + ":" + port;
        }
        if (StringUtils.isNotEmpty(serverContextPath) && !"/".equals(serverContextPath)) {
            apiServerContext = apiServerContext + serverContextPath;
        }

        return "access_by_lua_file hgg-lua/access_control.lua;\n" +
                "body_filter_by_lua_file hgg-lua/resBody.lua;\n" +
                "log_by_lua_file hgg-lua/logs.lua;\n" +
                "location /token {             #获取token服务\n" +
                "    proxy_pass   http://" + apiServerContext + "/token;\n" +
                "}\n" +
                "location /verify { #验证token服务\n" +
                "    internal;           #内部location，不能外部调用\n" +
                "    proxy_pass   http://" + apiServerContext + "/verify;\n" +
                "    proxy_set_header Content-type \"application/json\";\n" +
                "}";
    }
}
